#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include<vector>
//#include<bits/stdc+++.h>
using namespace std;

int dx[8] = { -1,0,1,-1,1,-1,0,1 };
int dy[8] = { -1,-1,-1,0,0,1,1,1 };
int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> arr(n, vector<int>(m));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> arr[i][j];

    vector<vector<int>> ret(n, vector<int>(m));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            if (arr[i][j] == 1) ret[i][j] = 9;
            else
            {
                for (int k = 0; k < 8; k++)
                {
                    int x = i + dx[k], y = j + dy[k];
                    if (x >= 0 && x < n && y >= 0 && y < m)
                        if(arr[x][y] == 1)
                            ret[i][j]++;
                }
            }
        }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
            cout << ret[i][j] << " ";
        cout << endl;
    }

    return 0;
}